package ApplicationStartTest.Bean;

import org.apache.hadoop.io.WritableComparable;
import org.springframework.stereotype.Component;
import scala.Function11;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


public class FlowBean implements WritableComparable<FlowBean> {

    private Long PhoneNumber;
    private Long UpFlowNum;
    private Long DownFlowNum;

    public FlowBean() {} //进行放射需要创建无参构造方法

    public FlowBean(Long phoneNumber, Long upFlowNum, Long downFlowNum) {
        PhoneNumber = phoneNumber;
        UpFlowNum = upFlowNum;
        DownFlowNum = downFlowNum;
    }

    public Long getPhoneNumber() {
        return PhoneNumber;
    }

    public void setPhoneNumber(Long phoneNumber) {
        PhoneNumber = phoneNumber;
    }

    public Long getUpFlowNum() {
        return UpFlowNum;
    }

    public void setUpFlowNum(Long upFlowNum) {
        UpFlowNum = upFlowNum;
    }

    public Long getDownFlowNum() {
        return DownFlowNum;
    }

    public void setDownFlowNum(Long downFlowNum) {
        DownFlowNum = downFlowNum;
    }

    public Long getSumFlow(){
        return this.DownFlowNum + this.UpFlowNum;
    }

    @Override
    public int compareTo(FlowBean o) {
        return this.getSumFlow() > o.getSumFlow() ? 1 : -1;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(this.PhoneNumber);
        out.writeLong(this.UpFlowNum);
        out.writeLong(this.DownFlowNum);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.PhoneNumber = in.readLong();
        this.UpFlowNum = in.readLong();
        this.DownFlowNum = in.readLong();
    }

    @Override
    public String toString() {
        return "FlowBean{" +
                "PhoneNumber=" + PhoneNumber +
                ", UpFlowNum=" + UpFlowNum +
                ", DownFlowNum=" + DownFlowNum +
                ", SumFlowNum=" + getSumFlow() +'}';
    }
}
